package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.common.security.service.TdfUser;
import com.engine4cloud.tdf.supervision.dto.JzdxAuditDTO;
import com.engine4cloud.tdf.supervision.dto.create.JzdxAuditCreateDTO;
import com.engine4cloud.tdf.supervision.dto.update.JzdxAuditDepartUpdateDTO;
import com.engine4cloud.tdf.supervision.entity.JzdxAuditResultEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;

@Mapper
public interface JzdxAuditResultConvert {
    JzdxAuditResultConvert INSTANCE = Mappers.getMapper(JzdxAuditResultConvert.class);

    JzdxAuditResultEntity create(JzdxAuditCreateDTO dto);

    default JzdxAuditResultEntity create(JzdxAuditCreateDTO dto, JzdxAuditDTO audit, TdfUser user) {
        //设置审核结果主信息
        JzdxAuditResultEntity entity = JzdxAuditResultConvert.INSTANCE.create(dto);
        //设置说明
        entity.setShsm(dto.getShsm());
        //设置状态
        entity.setShjg(audit.getStatus());
        //审核人
        entity.setShry(user.getUsername());
        //审核时间
        entity.setShsj(LocalDateTime.now());
        //设置部门流转信息
        entity.setPreDeptId(audit.getPreDeptId());
        //设置租户id
        entity.setTenantId(user.getTenantId());
        return entity;
    }

    default JzdxAuditDepartUpdateDTO update(String code, Long deptId) {
        JzdxAuditDepartUpdateDTO update = new JzdxAuditDepartUpdateDTO();
        update.setRybh(code);
        update.setDeptId(deptId);
        return update;
    }

}
